﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}
@section styles{
    <link href="@Url.Content("~/Content/css/common/fullcalendar/fullcalendar.min.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/common/fullcalendar/fullcalendar.print.min.css")" rel="stylesheet" media='print' />
    <style>
        #calendarbody {
            margin: 40px 10px;
            padding: 0;
            font-family: "Lucida Grande",Helvetica,Arial,Verdana,sans-serif;
            font-size: 14px;
        }

        #calendar {
            max-width: 900px;
            margin: 0 auto;
        }
    </style>
}
<div style="float:right;margin-right:175px;height:50px;margin-left:10px;">
    <div class="btn-wrap" style="position: fixed;">
        <a class="btn btn-sm btn-primary radius" onclick="select()" style="height:30px">
            查询日程
        </a>
    </div>
</div>

<body id="calendarbody">
    <div id="calendar">
    </div>
</body>

@section scripts{
    <script src="@Url.Content("~/Content/js/common/fullcalendar/moment.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/fullcalendar/jquery.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/fullcalendar/fullcalendar.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/fullcalendar/locale-all.js")"></script>
    <script src="@Url.Content("~/Content/js/layer/layer.js")"></script>
    <script>
        $(document).ready(function () {
            //var data = [
            //    {
            //       // id: 999,
            //        title: '上班',
            //        start: '2018-11-01',
            //        end: '2018-11-02',
            //       // type: '1',
            //        //level: '1',
            //        //editable: true
            //    }
            //];
           var data =@Html.Raw(@ViewData["calendarData"]);
            $('#calendar').fullCalendar({
                header: {
                    left: 'prevYear,prev,next,nextYear today',
                    center: 'title',
                    right: 'month,agendaWeek,agendaDay,listMonth'
                },//	设置日历头部信息。如果设置为false，则不显示头部信息
                defaultDate: '2018-11-01',
                locale: 'zh-cn',
                navLinks: true, // can click day/week names to navigate views
                selectable: true,
                theme: false,//是否允许使用jquery的ui主题，如果设置为true，则需要加载jquery ui相关css和js文件
                firstDay: 0,//设置一周中显示的第一天是哪天，周日是0，周一是1，类推。
                selectHelper: true,
                allDaySlot: true,
                allDayText:"全天",
                weekends: true,//	是否显示周末，设为false则不显示周六和周日
                contentHeight: 400,//设置日历主体内容的高度，不包括header部分，默认未设置，高度根据aspectRatio值自适应
               // minTime:0,//设置显示的时间从几点开始	0
              //  maxTime:24,	//设置显示的时间从几天结束	24
                timezone: 'local',//时区 默认，没有时区 ；'local'：客户机时区；'UTC'：世界标准时间
                select: function (start, end) {
                    location.href = "/Personal/Calendar/Edit?start="+start +"&end="+end;
                },
                editable: true,
                eventLimit: true, // allow "more" link when too many events
                events: data,
                eventClick: function (even) {
                    if (even) {
                        var id = even.id;
                        location.href = "/Personal/Calendar/Edit?id=" + id;
                    }
                }
            });
        });

        function select() {
            location.href = "/Personal/Calendar/Select";
        }

        function Edit_Layer(type, data) {
            var start;
            var startRemp;
            var end;
            var endTemp;
            if (type == '编辑日程') {

            }
            else {
                if (data) {
                    if (data[0]) {
                        startRemp = data[0].start;
                        if (startRemp) {
                            start = new Date(parseInt(startRemp._i)).toLocaleString();
                        }
                        endTemp = data[0].end;
                        if (endTemp) {
                            end = new Date(parseInt(endTemp._i)).toLocaleString();
                        }
                    }
                }
            }
            layer.open({
                id: 1,
                type: 1,
                title: type,
                skin: 'layui-layer-rim',
                area: ['550px', 'auto'],

                content: $(".layui-form"),
                btn: ['保存', '取消'],
                btn1: function (index) {
                    var content = $('#txtCONTENT').val();
                    var caltime = $('#txtCAL_TIME').val();
                    var endtime = $('#txtEND_TIME').val();
                    var caltype = $('#txtCAL_TYPE').val();
                    var callevel = $('#txtCAL_LEVEL').val();
                    var beforeremaind = $('#txtBEFORE_REMAIND').val();
                    var taker = $('#txtTAKER').val();
                    var allday = $('#txtALLDAY').val();
                    var eventData;
                    if (content) {
                        eventData = {
                            title: content,
                            start: startRemp,
                            end: endTemp,
                            caltype: caltype,
                            callevel: callevel,
                            beforeremaind: beforeremaind,
                            taker: taker
                        };

                        $('#calendar').fullCalendar('renderEvent', eventData, true); // stick? = true
                        $('#calendar').fullCalendar('unselect');
                        layer.close(index);
                    }
                },
                btn2: function (index) {
                    layer.close(index);
                }
            });
        }
    </script>
}
